import EventManager from "../EventManager";
import SceneManager from "./SceneManager";
import BButton from "../components/BButton";

const { ccclass, property } = cc._decorator;

/**
 * 界面基类，用于统一管理界面生命周期
 */
@ccclass
export default class StageBase extends cc.Component {

    @property(cc.Node)
    btnBack: cc.Node = null;

    protected hasCallOnLoad: boolean = false;

    onLoad() {
        console.log('切换到' + cc.js.getClassName(this) + '界面');
        EventManager.emit(SceneManager.Event_StageIn, this);
        if (this.btnBack) {
            BButton.addButton(this.btnBack).setTouchUpEvent(this.onBtnBackClick, this);
        }
    }

    onEnable() {

    }

    start() {

    }

    onDisable() {

    }

    onDestroy() {
        EventManager.emit(SceneManager.Event_StageOut, this);
        if (SceneManager.currStage == this) {
            SceneManager.currStage = null;
        }
    }

    protected onBtnBackClick() { }

}
